<?php

namespace app\admin\service\statistics\promotion\total;

use app\admin\service\statistics\promotion\AbstractComputeStatistician;
use app\admin\service\statistics\traits\CompletionTrait;
use function show_percentage;

/**
 * 渠道数据 总计 ROI
 * Class Roi
 * @package app\admin\service\statistics\promotion\total
 */
class Roi extends AbstractComputeStatistician
{
    // 补齐
    use CompletionTrait;

    // new_member_count,captcha_count
    protected function compute(int $index)
    {
        $statisticians = $this->statisticians;

        $pay_success_money = $statisticians['total-pay_success_money'][$index]['value'] ?? null;

        $refund_success_sum = $statisticians['total-refund_success_sum'][$index]['value'] ?? null;

        $roi_consume = $statisticians['total-roi_consume'][$index]['value'] ?? null;

        if (!is_numeric($pay_success_money) || !is_numeric($refund_success_sum) || !is_numeric($roi_consume) || $roi_consume == 0){
            return '';
        }

        return show_float($pay_success_money - $refund_success_sum, $roi_consume, 2);
    }

    protected function getDefaultValue()
    {
        return '0';
    }
}